#include "BDShape.h"

#include <QPoint>
#include <QImageReader>
#include <QPainterPath>

void BDCircle::Draw(QPainter* painter)
{
	if (painter == NULL) {
		return;
	}
	qDebug("BDCircle::Draw %d,%d", m_iCenter.x, m_iCenter.y);
	QBrush brushFill;
	QColor color;
	switch (m_color)
	{
	case BDCircle::BLACK:
		brushFill = QBrush(QColor(Qt::black));
		break;
	case BDCircle::RED:
		brushFill = QBrush(QColor(Qt::red));
		break;
	case BDCircle::GREEN:
		brushFill = QBrush(QColor(Qt::green));
		break;
	case BDCircle::YELLOW:
		brushFill = QBrush(QColor(Qt::yellow));
		break;
	case BDCircle::WHITE:
		brushFill = QBrush(QColor(Qt::white));
		break;
	default:
		break;
	}
	if (m_color == BDCircle::NONE)
		painter->setBrush(Qt::NoBrush);
	else
		painter->setBrush(brushFill);
	painter->drawEllipse(QPoint(m_iCenter.x, m_iCenter.y), m_iRadius, m_iRadius);
}

bool BDCircle::Contains(const BDCircle& other)
{
	QPainterPath path1;
	path1.addEllipse(QPoint(m_iCenter.x, m_iCenter.y), m_iRadius, m_iRadius);
	QPainterPath path2;
	path2.addEllipse(QPoint(other.m_iCenter.x, other.m_iCenter.y), other.m_iRadius, other.m_iRadius);
	return path1.contains(path2);
}

bool BDCircle::Intersects(const BDCircle& other)
{
	QPainterPath path1;
	path1.addEllipse(QPoint(m_iCenter.x, m_iCenter.y), m_iRadius, m_iRadius);
	QPainterPath path2;
	path2.addEllipse(QPoint(other.m_iCenter.x, other.m_iCenter.y), other.m_iRadius, other.m_iRadius);
	return path1.intersects(path2);
}

void BDLine::Draw(QPainter* painter)
{
	if (painter == NULL) {
		return;
	}
	painter->drawLine(QPoint(m_Point1.x, m_Point1.y), QPoint(m_Point2.x, m_Point2.y));
}

void BDImage::Draw(QPainter* painter)
{
	if (painter == NULL) {
		return;
	}
	QRect rect(m_Pos.x, m_Pos.y, m_Image.width() * m_Percent / 100, m_Image.height() * m_Percent / 100);
	painter->drawImage(rect, m_Image);
}

void BDString::Draw(QPainter* painter)
{
	if (painter == NULL) {
		return;
	}
	painter->drawText(QPoint(m_Pos.x, m_Pos.y), m_String);
}